package com.bit.springblogdemo.controller;

import com.bit.springblogdemo.pojo.request.UserLoginRequset;
import com.bit.springblogdemo.pojo.response.UserInfoResponse;
import com.bit.springblogdemo.pojo.response.UserLoginResponse;
import com.bit.springblogdemo.service.UserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.validation.constraints.NotNull;
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;

    /*用户登录*/
    @RequestMapping("/login")
    public UserLoginResponse login(@RequestBody  @Validated UserLoginRequset userLoginRequset) {
        log.info("用户登录");
        return userService.checkpassword(userLoginRequset);
    }
/*获取用户信息*/
    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull(message = "userId不能为空") Integer userId) {
        log.info("获取用户信息,userId:"+userId);
        return userService.getUserInfo(userId);
    }

/*获取读者信息*/
    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull(message = "blogId不能为空") Integer blogId) {
        log.info("获取读者信息 blogId:"+blogId);
        return userService.getAuthorInfo(blogId);
    }
}
